package com.cwj.film.controller;

import com.cwj.common.domain.film;
import com.cwj.common.vo.Result;
import com.cwj.common.vo.film.searchSo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/search")
public class searchController {
    @Resource
    private com.cwj.film.service.inter.search search;
    @PostMapping("/GetFilmListByTitle")
    private Result GetFilmListByTitle(searchSo searchSo) throws InvocationTargetException, IllegalAccessException {

        List<film> films = search.GetFilmListByTitle(searchSo.getTitle(), searchSo.getSize());
        films=films.stream().sorted(Comparator.comparing(film::getFid)).collect(Collectors.toList());
        return Result.normal(films,null);
    }
    @PostMapping("/GetFilmSizeByTitle")
    private Result GetFilmSizeByTitle(searchSo searchSo){
        Integer size = search.GetFilmSizeByTitle(searchSo.getTitle());
        return Result.normal(size,null);
    }
    @PostMapping("/GetFilmListByPageTitle")
    private Result GetFilmListByPageTitle(searchSo searchSo) throws InvocationTargetException, IllegalAccessException {
        List<film> films = search.GetFilmListByPageTitle(searchSo.getTitle(), searchSo.getSize(), searchSo.getPage());
        films=films.stream().sorted(Comparator.comparing(film::getFid)).collect(Collectors.toList());
        return Result.normal(films,null);
    }
}
